<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;


class LableController extends CommonController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
		$id = $_GET['id'];
		
		//小导航
		$dao = \DB::table("classone")->where('id',$id)->first();
		$pid = $dao->pid;
		$dao1 = \DB::table("classone")->where('id',$pid)->first();
		
		//商品推广
		$tui = \DB::table("tuiguang")->get();
		//侧边栏分类
		$list = \DB::table("classtwo")->where("pid",'=',0)->get();
		
		$pdata = \DB::table("classtwo")->where("pid",'>',0)->get();
		
		//网站配置
		$config = \DB::table("config")->get();
		
		//筛选
		$shaixuan = \DB::table("label")->get();
		
		//促销
		$cuxiao = \DB::table("list")->where('cuxiao',1)->get();
		
		$newGet = $_GET;
		unset($newGet['id']);
		  $arr = [];
	   $array = [];
	   $newArr = [];
	   
	  // var_dump($_GET);
	   foreach($newGet as $k => $v){
		   $arr[$k] = $k.'='.$v;
		   $newValue = explode("-",$v);
		   $array[] = '('.$k . ' >= ' . $newValue[0] . ' && ' . $k . ' <= ' . $newValue[1].')' ;
		   $newArr[$k][$k] = $v;
	   }
	   $idArr = [];
	   foreach($_GET as $k=>$v){
		   $idArr[$k] = $k.'='.$v;
	   }
	  
	   $newDelGet = [];
	   //var_dump($newArr);
	   foreach($newArr as $kk => $vv){
		   $delGet = $idArr;
		   unset($delGet[$kk]);
		   $newDelGet[$kk] = implode('&',$delGet);
		   
	   }
	   //var_dump($newDelGet);
	   $newQueryStrings = "&".implode('&',$arr);
	   $aa = implode(" && ",$array);
	   
	  // var_dump($aa);
	   $queryString = "&".implode('&',$arr);
	
	   $where = empty($aa) ? '' : " where pid={$id} && {$aa}";
	   //var_dump($where);die;
		$data = \DB::select("select * from list $where");
		
		
		return view("home.list.index",['list'=>$data,'list1'=>$list,'list2'=>$pdata,'config'=>$config,'tuiguang'=>$tui,
					'dao'=>$dao,'dao1'=>$dao1,'shaixuan'=>$shaixuan,'id'=>$id,'query'=>$queryString,'newDelGet'=>$newDelGet,'newArr'=>$newArr,'cuxiao'=>$cuxiao
		]);

	   
	  
		
	   
		  
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
